home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Graphics / Viewers / pCD0.3.4 / Source / Photo_CD.subproj / rotate.c < prev   
Encoding:
C/C++ Source or Header  |  1995-06-12  |  2.4 KB  |  110 lines

  1.  
  2. #include <stdlib.h>        //  on NeXT, at least
  3. #include <string.h>        //  on NeXT, at least
  4.  
  5. typedef unsigned char uBYTE;
  6. typedef unsigned long dim;
  7.  
  8. struct _implane
  9.  {dim  mwidth,mheight,
  10.        iwidth,iheight;
  11.   uBYTE *im;
  12.  };
  13. typedef struct _implane implane;
  14. enum TURNS  { T_NONE,T_RIGHT,T_LEFT };
  15.  
  16. extern planealloc();
  17.  
  18. void rotateBm( dim *wid, dim *ht, implane *r, implane *g, implane *b, enum TURNS t)
  19. {
  20.     dim x,y,w,h;
  21.     implane Out;
  22.     register uBYTE *pIn,*pOut;
  23.     uBYTE  *work;
  24.  
  25.     w = *wid, h = *ht;
  26.     work = malloc(h);
  27.     planealloc(&Out, w, h);
  28.     switch (t) {
  29.  
  30.        case T_RIGHT:
  31.           pOut = Out.im;
  32.           for( y=0; y<w; y++ ) {
  33.             pIn = r->im + r->mwidth * ( r->mheight -1) + y;
  34.              for( x=0; x<h; x++ ) {
  35.                work[x] = *pIn;    
  36.                 pIn -= r->mwidth;
  37.             }
  38.             bcopy(work, pOut, h);
  39.             pOut += h;
  40.           }
  41.           bcopy( Out.im, r->im, w*h);
  42.           pOut = Out.im;
  43.           for( y=0; y<w; y++ ) {
  44.             pIn = g->im + g->mwidth * ( r->mheight -1) + y;
  45.              for( x=0; x<h; x++ ) {
  46.                work[x] = *pIn;    
  47.                 pIn -= g->mwidth;
  48.             }
  49.             bcopy(work, pOut, h);
  50.             pOut += h;
  51.           }
  52.           bcopy( Out.im, g->im, w*h);
  53.           pOut = Out.im;
  54.           for( y=0; y<w; y++ ) {
  55.             pIn = b->im + b->mwidth * ( r->mheight -1) + y;
  56.              for( x=0; x<h; x++ ) {
  57.                work[x] = *pIn;    
  58.                 pIn -= b->mwidth;
  59.             }
  60.             bcopy(work, pOut, h);
  61.             pOut += h;
  62.           }
  63.           bcopy( Out.im, b->im, w*h);
  64.           break;
  65.        
  66.        case T_LEFT:
  67.           pOut = Out.im;
  68.           for( y=0; y<w; y++ ) {
  69.             pIn = r->im + r->mwidth - 1 - y;
  70.              for( x=0; x<h; x++ ) {
  71.                work[x] = *pIn;    
  72.                 pIn += r->mwidth;
  73.             }
  74.             bcopy(work, pOut, h);
  75.             pOut += h;
  76.           }
  77.           bcopy( Out.im, r->im, w*h);
  78.           pOut = Out.im;
  79.           for( y=0; y<w; y++ ) {
  80.             pIn = g->im + g->mwidth - 1 - y;
  81.              for( x=0; x<h; x++ ) {
  82.                work[x] = *pIn;    
  83.                 pIn += g->mwidth;
  84.             }
  85.             bcopy(work, pOut, h);
  86.             pOut += h;
  87.           }
  88.           bcopy( Out.im, g->im, w*h);
  89.           pOut = Out.im;
  90.           for( y=0; y<w; y++ ) {
  91.             pIn = b->im + b->mwidth - 1 - y;
  92.              for( x=0; x<h; x++ ) {
  93.                work[x] = *pIn;    
  94.                 pIn += b->mwidth;
  95.             }
  96.             bcopy(work, pOut, h);
  97.             pOut += h;
  98.           }
  99.           bcopy( Out.im, b->im, w*h);
  100.           break;
  101.        
  102.        default:    /* T_NONE (or something else) */
  103.           /* probably an internal error, but ignore for now */
  104.           break;
  105.     }
  106.     *wid = h, *ht = w;
  107.     free(Out.im);
  108.     free(work);
  109. }
  110.